home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 498 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Correctness of compilers behavior
  5. Date: 15 Feb 1996 15:42:47 GMT
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4fv5cb$9oj@fsuj01.rz.uni-jena.de>
  9. References: <3122157A.2EB2@orbotech.co.il>
  10. Reply-To: mkt@isun04.inf.uni-jena.de
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. Content-Type: text
  13. X-Nntp-Posting-Host: isun07.inf.uni-jena.de
  14. Content-Length: 838
  15. X-Lines: 21
  16. Originator: clamage@taumet
  17.  
  18. The array is created using 'new B[...]'. The SPARCompiler stores
  19. additional information when creating an array. This is neccessary
  20. in C++ to be able to call the destructor for all elements of the
  21. array on 'delete []'. At least it needs to store the number of elements
  22. of the array and the size of an individual element.
  23. ( class X {};
  24.   class Y : public X {};
  25.  
  26.   y = new Y[..];
  27.   delete [] (X*)y;  // sizeof(X) may be unequal to sizeof(Y);
  28. )
  29.  
  30. So the SPARCompiler also stores the information, which destructor to invoke!
  31. You can cast the pointer obtained from 'new B[...]' as often as you want
  32. and you can write code into your array as much as you want,
  33. the compiler uses the additional information stored with 'new B [...]'
  34. to destruct the array. And this information says: IT IS A 'B' ARRAY!
  35.  
  36. The code you wrote is simply not portable.
  37.  
  38.  
  39.  
  40. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  41.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  42.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  43. ]
  44.